<!-- 系统父组件容器 -->
<template>
  <div>
    <a-card :bordered="false">
      <a-tabs v-model="activeTab" @change="handleClickPane">
        <a-tab-pane
          key="1"
          :tab="$t('all.autotext1144')"
          v-if="$store.getters.project == null && $auth('SYSTEM.SYSTEM_ACCOUNT')"
        >
          <User ref="userRef" />
        </a-tab-pane>
        <a-tab-pane key="2" :tab="$t('all.autotext893')" v-if="$auth('SYSTEM.SYSTEM_ROLE')">
          <Role ref="roleRef" ></Role>
        </a-tab-pane>
        <a-tab-pane key="3" :tab="$t('all.autotext648')" v-if="$auth('SYSTEM.SYSTEM_PMS')">
          <a-tabs type="card">
            <a-tab-pane key="3-1" v-if="$store.getters.project == null" :tab="$t('all.autotext621')">
              <Pms :type="0"></Pms>
            </a-tab-pane>
            <a-tab-pane key="3-2" v-if="$store.getters.project != null" :tab="$t('all.autotext136')">
              <Pms :type="$const.SYSTEM_TYPE.PAYMENT.value"></Pms>
            </a-tab-pane>
            <a-tab-pane key="3-3" v-if="$store.getters.project != null" :tab="$t('all.autotext664')">
              <Pms :type="$const.SYSTEM_TYPE.MP.value"></Pms>
            </a-tab-pane>
            <!-- <a-tab-pane key="3-4" v-if="$store.getters.project != null" tab="项目权限-Pad">
              <Pms :type="$const.SYSTEM_TYPE.PAD.value"></Pms>
            </a-tab-pane> -->
          </a-tabs>
        </a-tab-pane>
        <a-tab-pane
          key="4"
          :tab="$t('all.autotext463')"
          v-if="$store.getters.project == null && $auth('SYSTEM.SYSTEM_SETTING')"
        >
          <Setting></Setting>
        </a-tab-pane>
        <a-tab-pane
          key="5"
          :tab="$t('all.autotext312')"
          v-if="$auth('SYSTEM.SYSTEM_DATA') && $store.getters.project == null"
        >
          <DataPms></DataPms>
        </a-tab-pane>
      </a-tabs>
    </a-card>
  </div>
</template>

<script>
import User from './components/user'
import Role from './components/role'
import Pms from './components/pms'
import Setting from './components/setting'
import DataPms from './components/data-pms'
import { PROJECT_CONFIG_CURRENT_TAB } from '@/store/mutation-types'

export default {
  name: 'System',
  components: {
    User,
    Role,
    Pms,
    Setting,
    DataPms
  },
  data () {
    return {
      activeTab: '1'
    }
  },
  mounted () {
    this.initActiveTab()
  },
  methods: {
    initActiveTab () {
      const authList = [
        this.$auth('SYSTEM.SYSTEM_ACCOUNT'),
        this.$auth('SYSTEM.SYSTEM_ROLE'),
        this.$auth('SYSTEM.SYSTEM_PMS'),
        this.$auth('SYSTEM.SYSTEM_SETTING'),
        this.$auth('SYSTEM.SYSTEM_DATA')
      ]
      const currentTab = this.$store.getters.currentTab
      this.activeTab = currentTab || String(authList.findIndex(Boolean) + 1)
    },
    handleClickPane (val) {
      this.storageCurrentTabKey(val)
      if (Number(val) === 1) {
        this.$nextTick(() => {
          this.$refs.userRef.refreshListData()
        })
      }
      if (Number(val) === 2) {
        this.$nextTick(() => {
          this.$refs.roleRef.refreshListData()
        })
      }
    },
    storageCurrentTabKey (val) {
      this.$store.commit(PROJECT_CONFIG_CURRENT_TAB, val)
    }
  }
}
</script>
<style scoped lang="scss"></style>
